package com.terrynoya.fight.stateMachine.triggers
{
	import com.terrynoya.fight.emuns.SymbolType;
	import com.terrynoya.fight.evaluation.ExpressionInterpretor;
	import com.terrynoya.fight.evaluation.Node;
	import com.terrynoya.fight.evaluation.ParseState;

	public class IfElse
	{
		public function IfElse()
		{
			
		}
		
		public static function eval(data:Object,node:Node):*
		{
			var test:Boolean = node.getChildAt(0).excute(data);
			var c1:* = node.getChildAt(1).excute(data);
			var c2:* = node.getChildAt(2).excute(data);
			if(test)
			{
				return c1;
			}
			else
			{
				return c2;
			}
		}
		
		public static function parse(state:ParseState):Node
		{
			if(state.currentSymbol != SymbolType.LeftParen)
			{
				return null;
			}
			state.tokenIndex ++;
			
			var c1:Node = state.buildNode(true);
			if(c1 == null)
			{
				return null;
			}
			state.baseNode.chilren.push(c1);
			
			if(state.currentSymbol != SymbolType.Comma)
			{
				return null;
			}
			state.tokenIndex ++;
			
			var c2:Node = state.buildNode(true);
			if(c2 == null)
			{
				return null;
			}
			state.baseNode.chilren.push(c2);
			
			if(state.currentSymbol != SymbolType.Comma)
			{
				return null;
			}
			state.tokenIndex ++;
			
			var c3:Node = state.buildNode(true);
			if(c3 == null)
			{
				return null;
			}
			state.baseNode.chilren.push(c3);
			
			if(state.currentSymbol != SymbolType.RightParen)
			{
				return null;
			}
			state.tokenIndex ++;
			
			return state.baseNode;
		}
	}
}